<?php include($SKIN . "ajax.inc.php");?>



{include file="header.inc.html"}
<style>
.sub{
	text-indent:30px;
}
.toggle,.editop{
	cursor:pointer;
}
</style>
<body class="layui-layout-body">
<div class="layui-layout layui-layout-admin">
	  {include file="left.inc.html"}  
	  <div class="layui-body">
		<!-- 内容主体区域 -->
		<div style="padding: 15px;">


			<div class="layui-breadcrumb">
			   {include file="where.inc.html"}
			</div>


			


			
			 
			{if isset($modes)}
			<div class="layui-layout-right ">
				{foreach $modes as $k => $v}
					<a href="{_url m='category' mid=$v.id }" class="layui-btn layui-btn-xs {if $mid==$v['id']}layui-btn-danger{/if}">{$v.name}</a>
				{/foreach}
			</div>
			{/if}

<div id="main_table_id">
		<table lay-filter="main_table_" class="layui-table" id="main_table">
		 
       <thead>
    <tr>
      <th  lay-data="{field:'id', width:100}">ID</th>
      <th lay-data="{field:'name', width:300,edit:'text'}">分类名</th>
      <th lay-data="{field:'name2', width:150,edit:'text'}">别名</th>

	  <th lay-data="{field:'porder', width:80,edit:'text'}">排序</th>


      <th lay-data="{field:'experience', width:70}">显示</th>
      
      
	  <th lay-data="{field:'count', width:80}">文章数</th>
      <th lay-data="{field:'sign', width:300}">操作</th>
    </tr> 
  </thead>
  <tbody>
	{$html_tr}
	</tbody>


  </table>  

</table></div>





			<button class="layui-btn layui-layout-rightxx add0 icon_add" >添加分类</button>
			{if checkAuth('news','index')}
			<a class="layui-btn layui-layout-rightxx" href="{url c='news' m='index' mid=$mid}">文章管理</a>
			{/if}
			{**###################################################**}
			
		</div>	
	  </div><!-- /layui-body -->


<script>



layui.use(['table','layer'], function(){
  var table = layui.table, $ = layui.$ , layer = layui.layer;

  //转换静态表格
	table.init('main_table_', {
	 // height: 500, //设置高度
	  limit: 30 //注意：请务必确保 limit 参数（默认：10）是与你服务端限定的数据条数一致
	  //支持所有基础参数
	}); 

	
	/*输出*/
	/*
	var tableIns = table.render({
		elem:'#main_table',
		cols:  [[ 
				//{checkbox: false},
				{field: 'num', title: '序号', width: 100,sort:true}
				,{field: 'tag', title: '唯一标识', width: 150,sort:true,edit:'text'}
			//	,{field: 'group_name', title: '所在分组', width: 150,toolbar:'#barGroupname'}
				,{field: 'name', title: '分类名称', width: 200,edit:'text'}
				,{field: 'desc', title: '简介', width: 120,sort:0,edit:'text'}

				
				//,{field: 'level', title: '分类等级', width: 100}
				,{field: 'status', title: '状态', width: 80,sort:0,edit:'text', templet: '#statusTpl'}
				 ,{field: 'porder', title: '排序', width: 80,edit:'text',sort:true}
				,{field: 'op', title: '操作', width: 300, toolbar: '#barDemo'}
			  ]],
		data : [],
		//url : '{_url m="indexmode" ajax=1}',
		//limits : [1,2,3,10],
		//limit : 1,
		page : false
	});
	*/

	$('#keyword').dblclick(function(){
		$(this).val('');
	});

	$('.demoTable .layui-btn').click(function(){
		tableIns.reload({
			where : {"keyword": $('#keyword').val()}
		});
	});
	$.each($('.add0'),function(){		
		$(this).click(function(){
			openPage('{_url m="addcategory" mid=$mid}','添加分类');
		});
	});	


	

	/*//监听工具条*/
	table.on('tool(main_table_)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
	  var data = obj.data; //获得当前行数据
	  var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
	  var tr = obj.tr; //获得当前行 tr 的DOM对象
	 
	  if(layEvent === 'add'){ //查看
		  openPage('{_url m="addcategory" mid=$mid}&fid='+data.id,'添加分类');

	  }else if(layEvent === 'field'){ 
		  /**/
		 

	  } else if(layEvent === 'del'){ //删除
		layer.confirm('真的删除本条信息么? ', function(index){
		  obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
		  layer.close(index);
		  //向服务端发送删除指令
		  $.get('{_url  m="dodeletecategory"}&id='+data.id,function(d){
			 d = gjson(d);
			 layui.layer.msg(d.msg);
		  });

		});
	  } else if(layEvent === 'edit'){ //编辑
		//do something
		openPage('{_url m="editcategory"}&id='+data.id,'编辑分类');		
		
		/*//同步更新缓存对应的值
		obj.update({
		  username: '123'
		  ,title: 'xxx'
		});*/
	 
	  }
	});

	doFastEdit('{_url m="dofastcategory"}', 'main_table_');

	
	
	if($('#select_mode').html() != undefined){
		layui.layer.open({
		  type: 1,
		  title : "请选择分类",
		  content: $('#select_mode') 
		});   

	}
	
	     
			


	
});


      

/*<input type="checkbox" name="status" value=1 checked lay-skin="switch">*/
</script>
{if !$mid && isset($modes)}
<div id="select_mode" style="display:none">
{foreach $modes as $k => $v}
	<a href="{_url m='category' mid=$v.id }" class="layui-btn">{$v.name}</a>
{/foreach}
</div>
{/if}
{html}
<script type="text/html" id="statusTpl">
 {{# if (d.status == 1) { }}		
		开启
	{{#  } else { }}
		关闭
	 {{#  } }}
</script>
{/html}

<script type="text/html" id="barGroupname">
<a class="layui-btn layui-btn-mini editgroup" lay-event="editgroup">{{d.group_name}}</a>
</script>
<script type="text/html" id="barDemo">  
  <a class="layui-btn layui-btn-mini field" lay-event="" href="{_url m='indexfield'}&mid={{d.id}}">字段管理({{d.total}})</a>

  <a class="layui-btn layui-btn-mini edit" lay-event="edit" data="{{d.id}}">编辑分类</a>
  <a class="layui-btn layui-btn-danger layui-btn-mini del" data="{{d.id}}" lay-event="del">删除分类</a>  

</script>

{include file="footer.inc.html"}


